package com.example.myapplicationndk.itemtouch;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

public class MmyItemTouchCallBack extends ItemTouchHelper.Callback {


    private ItemTouchHelperCallback mmyItemTouchCallBack;

    public MmyItemTouchCallBack(ItemTouchHelperCallback mmyItemTouchCallBack) {

        this.mmyItemTouchCallBack = mmyItemTouchCallBack;
    }


    @Override
    public int getMovementFlags(@NonNull @NotNull RecyclerView recyclerView, @NonNull @NotNull RecyclerView.ViewHolder viewHolder) {
        return makeMovementFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.END);
    }

    @Override
    public boolean onMove(@NonNull @NotNull RecyclerView recyclerView, @NonNull @NotNull RecyclerView.ViewHolder viewHolder, @NonNull @NotNull RecyclerView.ViewHolder target) {
        mmyItemTouchCallBack.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
        return true;
    }

    @Override
    public void onSwiped(@NonNull @NotNull RecyclerView.ViewHolder viewHolder, int direction) {


    }

    public interface ItemTouchHelperCallback {
        void onItemMove(int fromPosition, int toPosition);

        void onItemDelete(int position);

        void onItemChange(int lastSelectPos);

        int getLastSelectItem();
    }
}
